package edu.gxmzu.task.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.gxmzu.task.entity.Accounts;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface AccountsMapper extends BaseMapper<Accounts> {


    @Select("<script>" +
            "SELECT attachments_id FROM works WHERE user_id IN " +
            "<foreach collection='list' item='userId' open='(' close=')' separator=','>" +
            "  #{userId}" +
            "</foreach>" +
            "  AND attachments_id IS NOT NULL" +
            "</script>")
    List<Long> getAttachmentsIdsByUserIds(@Param("list") List<String> userIds);

    // 删除任务
    @Delete("<script>" +
            "DELETE FROM works WHERE user_id IN " +
            "<foreach collection='list' item='userId' open='(' close=')' separator=','>" +
            "  #{userId}" +
            "</foreach>" +
            "</script>")
    int deleteWorksByUserIds(@Param("list") List<String> userIds);


    // 删除附件
    @Delete("<script>" +
            "DELETE FROM attachments WHERE id IN " +
            "<foreach collection='list' item='id' open='(' close=')' separator=','>" +
            "  #{id}" +
            "</foreach>" +
            "</script>")
    int deleteAttachmentsByIds(@Param("list") List<Long> attachmentsIds);


    // 删除消息
    @Delete("<script>" +
            "DELETE FROM message WHERE user_id IN " +
            "<foreach collection='list' item='userId' open='(' close=')' separator=','>" +
            "#{userId}" +
            "</foreach>" +
            "</script>")
    int deleteMessagesByUserIds(@Param("list") List<String> userIds);

    @Delete("<script>" +
            "DELETE FROM accounts WHERE user_id IN " +
            "<foreach collection='list' item='userId' open='(' close=')' separator=','>" +
            "#{userId}" +
            "</foreach>" +
            "</script>")
    int deleteAccountById(@Param("list") List<String> userIds);
}
